﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using R = Szamlazz.Data.Request;

namespace Szamlazz.Data
{ 
	/// <summary>
	/// Azonositasi informaciok belso tarolatasanak megoldasara szolgal
	/// </summary>
	internal class Authentication
	{
		/// <summary>
		/// Konstruktor felhasznalo nevvel es jelszoval
		/// </summary>
		/// <param name="user">felhasznalo neve</param>
		/// <param name="password">jelszava</param>
		public Authentication(string user, string password)
		{
			this.User = user;
			this.Password = password;
		}

		/// <summary>
		/// Felhasznalo nev
		/// </summary>
		public string User { get; private set; }

		/// <summary>
		/// Belepesi jelszo
		/// </summary>
		public string Password { get; private set; }
		public virtual bool IsESigned { get { return false; } }

		/// <summary>
		/// Letrehozza a kereshez szukseges belso tipust az adatok alapjan
		/// </summary>
		/// <param name="downloadInstanceCount">letoltendo peldanyok szama a szamlabol (1 + masolatok szama)</param>
		/// <returns>az azonositashoz szukseges belso tipus</returns>
		internal virtual R.beallitasokTipus CreateForRequest(int downloadInstanceCount)
		{
			return new R.beallitasokTipus
			{
				felhasznalo = this.User,
				jelszo = this.Password,
				szamlaLetoltes = downloadInstanceCount > 0,
				szamlaLetoltesPldSpecified = downloadInstanceCount > 1,
				szamlaLetoltesPld = downloadInstanceCount > 1 ? downloadInstanceCount : 0,
				valaszVerzio = 2,
				valaszVerzioSpecified = true,
			};
		}
	}

	/// <summary>
	/// E-szamla bejelentkezesi adatok nyilvantartasa
	/// </summary>
	internal class EInvoiceAuthentication : Authentication
	{
		/// <summary>
		/// Kulcsszo e-szamla generalashoz
		/// </summary>
		public string Passphrase { get; private set; }

		/// <summary>
		/// Konstruktor
		/// </summary>
		/// <param name="user">felhasznalo</param>
		/// <param name="password">jelszo</param>
		/// <param name="passphrase">kulcsszo, e-szamla generalashoz</param>
		public EInvoiceAuthentication(string user, string password, string passphrase)
			: base(user, password)
		{
			this.Passphrase = passphrase;
		}

		/// <summary>
		/// Letrehozza az azonositashoz szukseges belso tipust
		/// </summary>
		/// <param name="downloadInstanceCount">letoltendo peldanyok szama a szamlabol (1 + masolatok szama)</param>
		/// <returns></returns>
		internal override R.beallitasokTipus CreateForRequest(int downloadInstanceCount)
		{
			var ret = base.CreateForRequest(downloadInstanceCount);

			ret.eszamla = true;
			ret.kulcstartojelszo = this.Passphrase;

			return ret;
		}

		public override bool IsESigned
		{
			get
			{
				return true;
			}
		}
	}
}
